using System.Collections.Generic;
using NHibernate.Validator.Constraints;
using SharpArch.Core.DomainModel;
using System;

namespace good1.Core
{
    public class Project : Entity
    {
        private Charity charity;
        private Location location;
        private IList<Photo> photos;
        private DateTime closingDate;
        private const int DefaultProjectLengthDays = 120;

        public Project()
        {
            if (charity == null) charity = new Charity();
            if (location==null) location = new Location();
            if (photos == null) photos = new List<Photo>();
            if (closingDate < DateTime.Today.AddDays(-1000)) closingDate = DateTime.Today.Date.AddDays(DefaultProjectLengthDays);
        }
		
		[NotNull, NotEmpty]
		public virtual string Title { get; set; }

		[NotNull, NotEmpty]
        [Length(1000000)]
        public virtual string Text { get; set; }

        [NotNull, NotEmpty]
        [Length(280)]
        public virtual string TagLine { get; set; }

        [NotNull, NotEmpty]
        [Length(280)]
        public virtual string YourDonationCan { get; set; }


        public virtual DateTime ClosingDate
        {
            get { return closingDate; }
            set { closingDate = value; }
        }

		public virtual int Amount { get; set; }

        public virtual int AmountRemaining { get; set; }

        public virtual string PhotoUrl { get; set; }

        public virtual int Priority { get; set; }
        //ALTER TABLE Projects ADD Priority INT NOT NULL CONSTRAINT PriorityIsZeroByDefault DEFAULT 10 

        public virtual Charity Charity
        //ALTER TABLE Projects ADD CharityFk INT
        {
            get{ return charity;}
            set { charity = value; }
        }

        public virtual Location Location
        {
            get { return location; }
            set { location = value; }
        }

        public virtual IList<Photo> Photos { get{ return photos;} set{ photos = value;} }


        public virtual Photo PhotoThumbnail
        {
            get
        {
            foreach (Photo photo in Photos)
            {
                if (photo.IsThumbnail) return photo;
            }
            return new Photo();
        } }

        public virtual IList<Tag> Tags { get; set; }

    }
}
